/*
 * @Author: your name
 * @Date: 2020-05-06 11:41:32
 * @LastEditTime: 2020-05-26 17:51:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /yigo/Store.js
 */
import {
    createStore,
    applyMiddleware,
    compose,
  } from 'redux';

import devTools from 'remote-redux-devtools';
import { composeWithDevTools } from 'redux-devtools-extension'


import { createLogger } from 'redux-logger'
import thunk from 'redux-thunk'
import api from './Api'
import RootRedurce from './src/Redurces/RootRedurce'

const logger = createLogger({
  // ...options
  // predicate:(a)=>{console.log('打印:',a);},     //每个action触发之前会调用这个方法
  collapsed:false,                                 //true的时候每个打印的action合起来
  duration:true,                                  //每个action持续的时间长短
  timestamp:true,                                 //每个action触发的时间戳
      // level:{level:'action'},                  //很神秘  不知道怎么用
  colors: {
      title: () => 'red',
      prevState: () => '#9E9E9E',
      action: () => '#03A9F4',
      nextState: () => '#4CAF50',
      error: () => '#F20404',
    },
  // titleFormatter:'dsds',
});

// const composeEnhancers = composeWithDevTools({
//   // Specify here name, actionsBlacklist, actionsCreators and other options
// });

// const enhancer = compose(
//   applyMiddleware(thunk,api,logger),
//   devTools({
//     name: Platform.OS,
//     hostname: 'localhost',
//     port: 5678,
//     suppressConnectErrors:false
//   })
// );

const createStoreWithMiddleware = composeWithDevTools(
  applyMiddleware(
    // middleware,
    thunk,
    api,
    logger,
  ),
  devTools({
      name: Platform.OS,
      hostname: 'localhost',
      port: 5678,
      suppressConnectErrors:false
    }),

)(createStore)

// const store = createStore(RootRedurce, composeEnhancers())
// export default store;
// 导出configureStore，里面携带着reducer，中间件，初始值
export default function configureStore(initialState){
  return createStoreWithMiddleware(RootRedurce,initialState);
}